package com.lh.controller;

import com.lh.entity.Article;
import com.lh.entity.PageBean;
import com.lh.entity.Result;
import com.lh.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;


    //新增文章
    @PostMapping("/addArticle")
    public Result addArticle(@RequestBody @Validated Article article) {
     return   articleService.addArticle(article);

    }

    //获取文章列表，并完成分页(由于需要返回的数据不仅是需要分页的数据还需要数据总量，所以需要重新封装PageBean
    @GetMapping("/articleList")
    public Result<PageBean> articleList(
            Integer pageNum,
            Integer pageSize,
 @RequestParam(required = false) Integer categoryId, //可传可不传参数
 @RequestParam(required = false) String state) {
     PageBean pageBean=   articleService.articleList(pageNum,pageSize,categoryId,state);
     return Result.success(pageBean);

    }
}
